package com.payment.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.payment.common.annotation.Log;
import com.payment.common.enums.BusinessType;
import com.payment.system.domain.AdministrativeDivision;
import com.payment.system.service.IAdministrativeDivisionService;
import com.payment.framework.web.base.BaseController;
import com.payment.common.page.TableDataInfo;
import com.payment.common.base.AjaxResult;
import com.payment.common.utils.ExcelUtil;

/**
 * 地区 信息操作处理
 * 
 * @author payment
 * @date 2018-12-26
 */
@Controller
@RequestMapping("/system/administrativeDivision")
public class AdministrativeDivisionController extends BaseController
{
    private String prefix = "system/administrativeDivision";
	
	@Autowired
	private IAdministrativeDivisionService administrativeDivisionService;
	
	@RequiresPermissions("system:administrativeDivision:view")
	@GetMapping()
	public String administrativeDivision()
	{
	    return prefix + "/administrativeDivision";
	}
	
	/**
	 * 查询地区列表
	 */
	@RequiresPermissions("system:administrativeDivision:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(AdministrativeDivision administrativeDivision)
	{
		startPage();
        List<AdministrativeDivision> list = administrativeDivisionService.selectAdministrativeDivisionList(administrativeDivision);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出地区列表
	 */
	@RequiresPermissions("system:administrativeDivision:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AdministrativeDivision administrativeDivision)
    {
    	List<AdministrativeDivision> list = administrativeDivisionService.selectAdministrativeDivisionList(administrativeDivision);
        ExcelUtil<AdministrativeDivision> util = new ExcelUtil<AdministrativeDivision>(AdministrativeDivision.class);
        return util.exportExcel(list, "administrativeDivision");
    }
	
	/**
	 * 新增地区
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存地区
	 */
	@RequiresPermissions("system:administrativeDivision:add")
	@Log(title = "地区", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(AdministrativeDivision administrativeDivision)
	{		
		return toAjax(administrativeDivisionService.insertAdministrativeDivision(administrativeDivision));
	}

	/**
	 * 修改地区
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		AdministrativeDivision administrativeDivision = administrativeDivisionService.selectAdministrativeDivisionById(id);
		mmap.put("administrativeDivision", administrativeDivision);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存地区
	 */
	@RequiresPermissions("system:administrativeDivision:edit")
	@Log(title = "地区", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(AdministrativeDivision administrativeDivision)
	{		
		return toAjax(administrativeDivisionService.updateAdministrativeDivision(administrativeDivision));
	}
	
	/**
	 * 删除地区
	 */
	@RequiresPermissions("system:administrativeDivision:remove")
	@Log(title = "地区", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(administrativeDivisionService.deleteAdministrativeDivisionByIds(ids));
	}

	/**
	 * 根据上级id查询指定市或区
	 * @return
	 */
	@RequestMapping( "/getRegionByParentId")
	@ResponseBody
	public AjaxResult getRegionByParentId(String  parentId)

	{
		return AjaxResult.successAndData("获取城市信息成功",administrativeDivisionService.getRegionByParentId(parentId));
	}


}
